package hx.front.manager.seeker;

import hx.engine.IHouseEngine;
import hx.engine.ISectorEngine;
import hx.front.manager.SeekerAction;
import hx.model.dto.House;
import hx.model.dto.Sector;

import java.util.ArrayList;
import java.util.Collection;

public class SectorSeeker extends SeekerAction {

	private static final long serialVersionUID = 1L;

	private static final String SECTOR_SEEKER = "buscadorSectores";

	private ISectorEngine sectorEngine;

	private String houseId;
	private Collection<House> houseList = new ArrayList<House>();
	private Collection<Sector> sectorList = null;

	private IHouseEngine houseEngine;

	@Override
	public String execute() throws Exception {
		loadCollections();
		return SECTOR_SEEKER;
	}

	@Override
	protected void loadCollections() throws Exception {
		houseList = houseEngine.findAll();
	}

	@Override
	public String search() {
		// Deshacemos el null para devolver la tabla existan o no resultados.
		sectorList = new ArrayList<Sector>();
		sectorList.addAll(sectorEngine.findByHouse(new House(getHouseId())));
		return SECTOR_SEEKER;
	}

	// GETTERS AND SETTERS
	public ISectorEngine getSectorEngine() {
		return sectorEngine;
	}

	public void setSectorEngine(ISectorEngine sectorEngine) {
		this.sectorEngine = sectorEngine;
	}

	public IHouseEngine getHouseEngine() {
		return houseEngine;
	}

	public void setHouseEngine(IHouseEngine houseEngine) {
		this.houseEngine = houseEngine;
	}

	public Collection<House> getHouseList() {
		return houseList;
	}

	public void setHouseList(Collection<House> houseList) {
		this.houseList = houseList;
	}

	public Collection<Sector> getSectorList() {
		return sectorList;
	}

	public void setSectorList(Collection<Sector> sectorList) {
		this.sectorList = sectorList;
	}

	public String getHouseId() {
		return houseId;
	}

	public void setHouseId(String houseId) {
		this.houseId = houseId;
	}

}
